home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / option.exe / THEAPAPP.CPP < prev    next >
C/C++ Source or Header  |  1992-10-25  |  2KB  |  103 lines

  1. #define Uses_TApplication
  2. #define Uses_THeapApp
  3. #define Uses_TRect
  4. #define Uses_TView
  5. #define Uses_TDrawBuffer
  6. #include <tv.h>
  7. #include "THeapApp.h"
  8.  
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <ctype.h>
  12. #include <strstrea.h>
  13. #include <iomanip.h>
  14. #include <alloc.h>
  15. #include <time.h>
  16.  
  17. /*---------------------------------------------------------*/
  18. /*                                                         */
  19. /*   Turbo Vision 1.0                                      */
  20. /*   Copyright (c) 1991 by Borland International           */
  21. /*                                                         */
  22. /*   THeapView class free heap display                     */
  23. /*---------------------------------------------------------*/
  24.  
  25. //
  26. // ------------- Heap Viewer functions
  27. //
  28.  
  29. THeapView::THeapView(TRect& r) : TView( r )
  30. {
  31.     oldMem = 0;
  32.     newMem = heapSize();
  33. }
  34.  
  35.  
  36. void THeapView::draw()
  37. {
  38.     TDrawBuffer buf;
  39.     char c = getColor(2);
  40.  
  41.     buf.moveChar(0, ' ', c, size.x);
  42.     buf.moveStr(0, heapStr, c);
  43.     writeLine(0, 0, size.x, 1, buf);
  44. }
  45.  
  46.  
  47. void THeapView::update()
  48. {
  49.     if( (newMem = heapSize()) != oldMem )
  50.         {
  51.         oldMem = newMem;
  52.         drawView();
  53.         }
  54. }
  55.  
  56.  
  57. long THeapView::heapSize()
  58. {
  59.     long total = farcoreleft();
  60.     struct farheapinfo heap;
  61.     ostrstream totalStr( heapStr, sizeof heapStr);
  62.  
  63.     switch( farheapcheck() )
  64.         {
  65.         case _HEAPEMPTY:
  66.             strcpy(heapStr, "     No heap");
  67.             total = -1;
  68.             break;
  69.  
  70.         case _HEAPCORRUPT:
  71.             strcpy(heapStr, "Heap corrupt");
  72.             total = -2;
  73.             break;
  74.  
  75.         case _HEAPOK:
  76.             heap.ptr = NULL;
  77.             while(farheapwalk(&heap) != _HEAPEND)
  78.                 if(!heap.in_use)
  79.                     total += heap.size;
  80.             totalStr << setw(12) << total << ends;
  81.             break;
  82.         }
  83.     return(total);
  84. }
  85.  
  86. THeapApp::THeapApp() :
  87.     TProgInit( &THeapApp::initStatusLine,
  88.                &THeapApp::initMenuBar,
  89.                &THeapApp::initDeskTop
  90.              )
  91.     {
  92.     TRect r = getExtent();
  93.     r.a.x = r.b.x - 13;     r.a.y = r.b.y - 1;
  94.     heap = new THeapView( r );
  95.     insert(heap);
  96.     }
  97.  
  98. void THeapApp::idle()
  99.     {
  100.     TProgram::idle();
  101.     heap->update();
  102.     }
  103.